package com.zpb.admin.controller;

import com.zpb.framework.domain.ApiResult;
import com.zpb.framework.domain.dto.ArticleAddDto;
import com.zpb.framework.domain.dto.ArticleEditDto;
import com.zpb.framework.domain.dto.ArticleQueryDto;
import com.zpb.framework.domain.vo.ArticleEditVo;
import com.zpb.framework.domain.vo.PageVo;
import com.zpb.framework.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: zhaopengbo
 * @Date: 2025/9/20
 */
@RestController
@RequestMapping("/content/article")
public class ContentArticleController {
    @Autowired
    private ArticleService articleService;
    @PostMapping
    public ApiResult addArticle(@RequestBody ArticleAddDto articleAddDto) {
        return articleService.addArticle(articleAddDto);
    }
    @GetMapping("/list")
    public ApiResult<PageVo> getArticleList(@RequestParam(defaultValue = "1") Integer pageNum,
                                            @RequestParam(defaultValue = "10") Integer pageSize,
                                            ArticleQueryDto articleQueryDto) {
        return articleService.getArticleListByCondition(pageNum,pageSize,articleQueryDto);
    }
    @GetMapping("/{id}")
    public ApiResult<ArticleEditVo> getArticle(@PathVariable Long id) {
        return articleService.getArticleById(id);
    }
    @PutMapping
    public ApiResult updateArticle(@RequestBody ArticleEditDto articleEditDto) {
        return articleService.updateArticleById(articleEditDto);
    }
    @DeleteMapping("/{id}")
    public ApiResult deleteArticle(@PathVariable Long id) {
        return articleService.deleteArticleById(id);
    }
}
